//
//  MOChangePasswordViewCell.m
//  MobileOffice
//
//  Created by 冰冰 on 2019/6/2.
//  Copyright © 2019 com.idolmedia. All rights reserved.
//

#define buttonW  90
#import "MOChangePasswordViewCell.h"

@interface MOChangePasswordViewCell ()<UITextFieldDelegate>

@property(nonatomic,strong)UILabel *nameLabel;

@property(nonatomic,strong)UIButton *getCodeButton;

@end

@implementation MOChangePasswordViewCell

+(instancetype)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath
{
    NSString *ID = @"MOChangePasswordViewCell";
    MOChangePasswordViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil){
        cell = [[MOChangePasswordViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatView];
    }
    return cell;
}


-(void)creatView
{
    [self addSubview:self.nameLabel];
    [self addSubview:self.textField];
    [self addSubview:self.getCodeButton];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"%@",textField.text);
    return YES;
}

-(void)setModel:(MOChangePasswordModel *)model
{
    if ([model.type integerValue]==1) {//获取验证码
        self.textField.width = SCREEN_WIDTH - 30 - 90;
        self.getCodeButton.hidden = NO;
    }else{
        self.textField.width = SCREEN_WIDTH - 30;
        self.getCodeButton.hidden = YES;
    }
    self.nameLabel.text = model.nameStr;
    self.textField.placeholder = model.placeStr;
}

- (void)clickCodeButton{
    [self.getCodeButton SG_countdownWithSecond:60];
    if (self.clickCodeBlock) {
        self.clickCodeBlock();
    }
}


#pragma mark -- 懒加载
-(UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, kHConversions(20), SCREEN_WIDTH-30, 12)];
        _nameLabel.font = FONT_SIZE(12);
        _nameLabel.textColor = KBlackColor_2A2A2A;
    }
    return _nameLabel;
}

-(UITextField *)textField
{
    if (!_textField) {
        _textField = [[UITextField alloc]initWithFrame:CGRectMake(15, _nameLabel.bottom+kHConversions(12), SCREEN_WIDTH-30, 15)];
        _textField.delegate = self;
        _textField.font = FONT_SIZE(15);
    }
    return _textField;
}

-(UIButton *)getCodeButton
{
    if (!_getCodeButton) {
        _getCodeButton = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 15 - 90, _nameLabel.bottom+kHConversions(12), 90, 15)];
        _getCodeButton.titleLabel.font = FONT_SIZE(12);
        [_getCodeButton setTitle:@"获取短信验证码" forState:UIControlStateNormal];
        [_getCodeButton setTitleColor:KBlueColor_2C94FF forState:UIControlStateNormal];
        [_getCodeButton addTarget:self action:@selector(clickCodeButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _getCodeButton;
}



@end
